package cn.iocoder.yudao.module.bpm.controller.admin.tbcheck;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.bpm.controller.admin.tbcheck.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.tbcheck.TbCheckDO;
import cn.iocoder.yudao.module.bpm.convert.tbcheck.TbCheckConvert;
import cn.iocoder.yudao.module.bpm.service.tbcheck.TbCheckService;

@Api(tags = "aaa管理后台 - 图斑检查审批")
@RestController
@RequestMapping("/bpm/tb-check")
@Validated
public class TbCheckController {

    @Resource
    private TbCheckService tbCheckService;

    @PostMapping("/create")
    @ApiOperation("创建图斑检查审批")
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:create')")
    public CommonResult<Long> createTbCheck(@Valid @RequestBody TbCheckCreateReqVO createReqVO) {
        return success(tbCheckService.createTbCheck(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新图斑检查审批")
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:update')")
    public CommonResult<Boolean> updateTbCheck(@Valid @RequestBody TbCheckUpdateReqVO updateReqVO) {
        tbCheckService.updateTbCheck(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除图斑检查审批")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:delete')")
    public CommonResult<Boolean> deleteTbCheck(@RequestParam("id") Long id) {
        tbCheckService.deleteTbCheck(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得图斑检查审批")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:query')")
    public CommonResult<TbCheckRespVO> getTbCheck(@RequestParam("id") Long id) {
        TbCheckDO tbCheck = tbCheckService.getTbCheck(id);
        return success(TbCheckConvert.INSTANCE.convert(tbCheck));
    }

    @GetMapping("/list")
    @ApiOperation("获得图斑检查审批列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:query')")
    public CommonResult<List<TbCheckRespVO>> getTbCheckList(@RequestParam("ids") Collection<Long> ids) {
        List<TbCheckDO> list = tbCheckService.getTbCheckList(ids);
        return success(TbCheckConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得图斑检查审批分页")
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:query')")
    public CommonResult<PageResult<TbCheckRespVO>> getTbCheckPage(@Valid TbCheckPageReqVO pageVO) {
        PageResult<TbCheckDO> pageResult = tbCheckService.getTbCheckPage(pageVO);
        return success(TbCheckConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出图斑检查审批 Excel")
    @PreAuthorize("@ss.hasPermission('bpm:tb-check:export')")
    @OperateLog(type = EXPORT)
    public void exportTbCheckExcel(@Valid TbCheckExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<TbCheckDO> list = tbCheckService.getTbCheckList(exportReqVO);
        // 导出 Excel
        List<TbCheckExcelVO> datas = TbCheckConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "图斑检查审批.xls", "数据", TbCheckExcelVO.class, datas);
    }

}
